<template>
    <view class="pwd-reset box pd-v-72 ">
  
      <view class="full-w box mr-t-40">
          
          <view>
              <u--form
                  :model="form"
                  :rules="rules"
                  ref="uForm"
              >
                  <u-form-item
                      prop="oldPassword"
                  >
                      <u--input
                          v-model="form.oldPassword"
                          border="none"
                          shape="circle"
                          :customStyle="{backgroundColor:'#F5F5F5',height:'108rpx',padding:'0 40rpx'}"
                          type="password"
                          placeholder="旧密码"
                      ></u--input>
                  </u-form-item>
                  <u-form-item
                      class="mr-t-32"
                      prop="newPassword"
                  >
                      <u--input
                          v-model="form.newPassword"
                          border="none"
                          shape="circle"
                          :customStyle="{backgroundColor:'#F5F5F5',height:'108rpx',padding:'0 40rpx'}"
                          type="password"
                          placeholder="新密码"
                      ></u--input>
                  </u-form-item>
                  <u-form-item
                      class="mr-t-32"
                      prop="passwordRepeat"
                  >
                      <u--input
                          v-model="form.passwordRepeat"
                          border="none"
                          shape="circle"
                          :customStyle="{backgroundColor:'#F5F5F5',height:'108rpx',padding:'0 40rpx'}"
                          type="password"
                          placeholder="确认新密码"
                      ></u--input>
                  </u-form-item>
              </u--form>
          </view>
            
        
          <view class="full-w box mr-t-60 pd-v-40">
              <u-button type="primary" :customStyle="{height:'88rpx'}" shape="circle" color="#35BE65" @click="save"  text="保存"></u-button>
          </view>
      </view>
  
    </view>
  </template>
  
  <script setup>
  
  import { useStore } from '@/store/index.js';
  
  import { agentAndPartnerCommonUpdatePwd } from "@/api/proxy.js";
  
  import { computed, ref, onMounted, reactive } from "vue";
  import { onReady } from '@dcloudio/uni-app';
  
  const store = useStore();
  
  const isCheck = ref(false)
  const form = ref({
      oldPassword: '',
      newPassword: '',
      passwordRepeat:''
  });
  const uForm = ref(null);
  const rules = ref({
      oldPassword: [
          {
              required: true,
              message: '请输入旧密码',
              trigger: ['blur','change'],
          }
      ],
      newPassword: [
          {
              required: true,
              message: '请输入新密码',
              trigger:  ['blur','change'],
          }
      ],
      passwordRepeat: [
          {
              trigger:  ['blur','change'],
              validator: (rule, value, callback) => {
                  console.log(value,'vvvvvvvvvvvvv')
                  if (!value) {
                      
                      callback('请确认新密码')
  
                      return false;
                  }
                  if (value != form.value.newPassword) {
                      callback('两次密码不一致')
  
                      return false;
                  }
  
                  return true
              }
          }
      ]
  })
  
  onReady(() => {
      console.log(uForm.value)
      uForm.value.setRules(rules.value)
  });
  
  onMounted(() => {
  });
  
  const save = () => {
      uForm.value.validate().then(res => {
          if(res) {
              uni.showLoading({
                  title: '修改中...',
                  mask: true
              });
              
              agentAndPartnerCommonUpdatePwd({...form.value,userId:store?.user?.userInfo2?.userId}).then(res => {
                  uni.hideLoading()
                  if(res.code == 200) {
                      
                      uni.showToast({
                          title: '修改成功',
                          icon: 'success'
                      });
                      setTimeout(() => {
                          uni.navigateBack({
                              delta: 1
                          })
                      }, 1000);
                  } else {
                      uni.showToast({
                          title: res.msg,
                          icon: 'none'
                          
                      });
  
                  }
              }).catch(err => {
                  uni.hideLoading()
                  uni.showToast({
                      title: '修改失败',
                      icon: 'none'
                  });
              })
          }
      }).catch(err => {
          console.log(err)
      })
  }
  
  </script>
  
  <style lang="scss" scoped>
  .pwd-reset {
      height:100vh;
      
  
      .pwd-reset__footer  {
          left:0;
          bottom:68rpx;
      }
  }
  </style>
  